﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Stauffware.Common.Core
{
	//#################################################################################
	/// <summary>
	/// Parser for signed byte values (System.SByte).
	/// </summary>

	public class SByteParser : IntegerParser<sbyte, SByteParse>
	{ 
		/// <summary>
		/// Constructs a parser that uses NumberParseOptions.DefaultParseOptions.
		/// </summary>
		public SByteParser ( ) : base(DefaultParseOptions, null) { }

		/// <summary>
		/// Constructs a parser.
		/// </summary>
		/// <param name="options">parsing options</param>
		public SByteParser (NumberParseOptions options) : base(options, null) { }

		/// <summary>
		/// Constructs a parser that uses NumberParseOptions.DefaultParseOptions.
		/// </summary>
		/// <param name="ifp">formatting info, or null</param>
		public SByteParser (IFormatProvider ifp) : base(NumberParseOptions.None, ifp) { }

		/// <summary>
		/// Constructs a parser.
		/// </summary>
		/// <param name="options">parsing options</param>
		/// <param name="ifp">formatting info, or null</param>
		public SByteParser (NumberParseOptions options, IFormatProvider ifp) : base(options, ifp) { }

		/// <summary>
		/// Gets the maximum number of digits (base 10) that a number can have.
		/// </summary>
		protected override int MaxDigits { get { return 3; } }

		/// <summary>
		/// Gets the maximum number of digits that can appear in an exponent.
		/// </summary>
		protected override int MaxExponentDigits { get { return 0; } }

		/// Gets whether this parser's target type is signed.
		protected override bool Signed { get { return true; } }

	//	/// Creates a Parse object of the proper class for this Parser.
	//	protected override IntegerParse<sbyte> CreateParseObject ()
	//	{ return new SByteParse(); }

		/// Attempts a parse of a normalized integer string.  (see IntegerParser.TryParse)
		protected override bool TryParse (string str, out sbyte value)
		{ return sbyte.TryParse(str, out value); }

	}

	//=================================================================================
	/// <summary>
	/// Encapsulates the result of trying to parse a string into an sbyte value.
	/// </summary>

	public class SByteParse : IntegerParse<sbyte>
	{
	}

	//#################################################################################
	/// <summary>
	/// Parser for unsigned byte values (System.Byte).
	/// </summary>

	public class ByteParser : IntegerParser<byte, ByteParse>
	{
		/// <summary>
		/// Constructs a parser that uses NumberParseOptions.DefaultParseOptions.
		/// </summary>
		public ByteParser ( ) : base(DefaultParseOptions, null) { }

		/// <summary>
		/// Constructs a parser.
		/// </summary>
		/// <param name="options">parsing options</param>
		public ByteParser (NumberParseOptions options) : base(options, null) { }

		/// <summary>
		/// Constructs a parser that uses NumberParseOptions.DefaultParseOptions.
		/// </summary>
		/// <param name="ifp">formatting info, or null</param>
		public ByteParser (IFormatProvider ifp) : base(NumberParseOptions.None, ifp) { }

		/// <summary>
		/// Constructs a parser.
		/// </summary>
		/// <param name="options">parsing options</param>
		/// <param name="ifp">formatting info, or null</param>
		public ByteParser (NumberParseOptions options, IFormatProvider ifp) : base(options, ifp) { }

		/// <summary>
		/// Gets the maximum number of digits (base 10) that a number can have.
		/// </summary>
		protected override int MaxDigits { get { return 3; } }

		/// <summary>
		/// Gets the maximum number of digits that can appear in an exponent.
		/// </summary>
		protected override int MaxExponentDigits { get { return 0; } }

		/// <summary>
		/// Gets whether this parser's target type is signed.
		/// </summary>
		protected override bool Signed { get { return false; } }

	//	/// Creates a Parse object of the proper class for this Parser.
	//	protected override IntegerParse<byte> CreateParseObject ()
	//	{ return new ByteParse(); }

		/// Attempts a parse of a normalized integer string.  (see IntegerParser.TryParse)
		protected override bool TryParse (string str, out byte value)
		{ return byte.TryParse(str, out value); }
	}

	//=================================================================================
	/// <summary>
	/// Encapsulates the result of trying to parse a string into a byte value.
	/// </summary>

	public class ByteParse : IntegerParse<byte>
	{
	}

	//#################################################################################
}
